<?php 

class Content extends AppModel
{
	var $name = 'Content';
	
	var $fieldProperties = array(
	
		'model' => array(
			'type' => 'select',
			'empty' => '-Select-',
			'group' => 'add',
			'label' => 'Content Type',
			'options' => array('Listing'=>'Listings', 'Review'=>'Reviews', 'User' => 'Users', 'ReviewComment'=>'ReviewComments'),
			'triggers' => array('onChange' => array('update' => 'scope')),
			'class'=>"scope_model_select",
		),
		
		'scope' => array(
			'type' => 'select',
			'empty' => '-Select-',
			'group' => 'add',
		),

	);
	function initialize()
	{
		$this->fieldProperties['scope']['label'] = __("Filter")." &nbsp;&nbsp;&nbsp;(<a href=\"javascript:void(0);\" class=\"addNewScope\" onclick=\"addScope(this)\">".__("Define new")."</a>)"; 
		parent::initialize();
	}
	function getScopeOptions($contentType)
	{
		$options = array();
		$contentType_plural = Inflector::pluralize($contentType);
		$restictedActions = array('my','tags','myfavorite','user','category','advancedSearch','search','listing');
		if(cr('ReviewConfig.allow_comment') != '1')
		{
			array_push($restictedActions,'most_commented');
		}
		$methods = (array)cr('indexMethods.'.$contentType_plural);
		foreach($methods as $key => $method)
		{			
			if(in_array($key, $restictedActions))
			{
				continue;
			}
			if(isset($method['title']))
			{
				$options[$key] = $method['title'];
			}
		}	
		$conditions = array('ContentScope.model' => $contentType);
		$userDefinedScopes = cri('ContentScope')->find('list', compact('conditions'));
		//not using am() as it changes the numeric key value. 
		foreach($userDefinedScopes as $scopeId => $title)
		{
			$options[$scopeId] = $title;
		}
		return $options;
	}
}

?>